package ui;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Display;

public class GetServerAddressScreen extends Form implements CommandListener{
    private TextField thisAddressField;
    private Command exitCommand;
    private Command agentPlatformSetupCommand;
	private manager.AgentManagerMIDlet midlet;
    private Display display;
	
	public GetServerAddressScreen(manager.AgentManagerMIDlet midlet,Display display){
		super("Please enter in Server address.");
		this.display = display;
		this.midlet = midlet;
		thisAddressField = new TextField("Enter in your address", "socket://:5000", 50, TextField.ANY);
		this.append(thisAddressField);
        exitCommand = new Command("Exit", Command.EXIT, 1);
        agentPlatformSetupCommand = new Command("Create Agent Manager",Command.SCREEN,4);
        this.addCommand(exitCommand);
        this.addCommand(agentPlatformSetupCommand);
        this.setCommandListener(this);
	}
	
	
	public void commandAction(Command c, Displayable d){
	        if (c == exitCommand){
	            midlet.exitRequested();
	        }else if(c == agentPlatformSetupCommand){
	        	midlet.createIOHandlerManager(thisAddressField.getString());
	        	ui.AgentCreationScreen creationScreen = 
	            	new ui.AgentCreationScreen(midlet, "Please Select an Agent to create",display);
	        	display.setCurrent(creationScreen);
	        }
	    }
	  
}
